package com.example.demo.entity.PO;

import com.example.demo.enums.PropTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Optional;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class PropPO {

    private Integer id;

    private Integer userId;

    private Integer propId;

    private PropTypeEnum type;

    private String name;
    /**
     * 数量
     */
    private Integer amount;

    /**
     * 该行数据创建时间
     */
    private Long createdAt;

    /**
     * 该行数据修改时间
     */
    private Long updatedAt;

    public Integer getType() {
        return Optional.ofNullable(type).map(PropTypeEnum::getId).orElse(null);
    }

    public void setType(Integer type) {
        this.type = PropTypeEnum.getTypeById(type);
    }
}
